Imports System
Imports System.Configuration
Imports System.Web.Configuration

Partial Class Usercontrols_Admin_OptionsSettings
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.Page.IsPostBack = False Then
            LoadSettings()
        End If

        Me.uxAdminPanel.Visible = ShowControls(SecurityMask.Admin, True)

    End Sub

#End Region

#Region " Save Data "

    Public Sub SaveSettings()
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then

            If IsNothing(AppSettingsSection.Settings("EnableFavorites")) Then
                AppSettingsSection.Settings.Add("EnableFavorites", Me.uxEnableFavoritesCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableFavorites").Value() = Me.uxEnableFavoritesCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableRating")) Then
                AppSettingsSection.Settings.Add("EnableRating", Me.uxEnableRatingCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableRating").Value() = Me.uxEnableRatingCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableTags")) Then
                AppSettingsSection.Settings.Add("EnableTags", Me.uxEnableTagsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableTags").Value() = Me.uxEnableTagsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableComments")) Then
                AppSettingsSection.Settings.Add("EnableComments", Me.uxEnableCommentsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableComments").Value() = Me.uxEnableCommentsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableTools")) Then
                AppSettingsSection.Settings.Add("EnableTools", Me.uxEnableToolsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableTools").Value() = Me.uxEnableToolsCheckbox.Checked
            End If

            configuration.Save()
        End If

    End Sub

    Public Sub SaveSettings(ByVal key As String, ByVal value As String)
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim appSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (appSettingsSection Is Nothing) Then
            appSettingsSection.Settings(key).Value = value
            configuration.Save()
        End If
    End Sub

#End Region

#Region " Load Data "

    Public Sub LoadSettings()

        If Not (AppSettingsSection Is Nothing) Then
            If IsNothing(AppSettingsSection.Settings("EnableFavorites")) Then
                Me.uxEnableFavoritesCheckbox.Checked = True
            Else
                Me.uxEnableFavoritesCheckbox.Checked = AppSettingsSection.Settings("EnableFavorites").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableRating")) Then
                Me.uxEnableRatingCheckbox.Checked = True
            Else
                Me.uxEnableRatingCheckbox.Checked = AppSettingsSection.Settings("EnableRating").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableTags")) Then
                Me.uxEnableTagsCheckbox.Checked = True
            Else
                Me.uxEnableTagsCheckbox.Checked = AppSettingsSection.Settings("EnableTags").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableComments")) Then
                Me.uxEnableCommentsCheckbox.Checked = True
            Else
                Me.uxEnableCommentsCheckbox.Checked = AppSettingsSection.Settings("EnableComments").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableTools")) Then
                Me.uxEnableToolsCheckbox.Checked = True
            Else
                Me.uxEnableToolsCheckbox.Checked = AppSettingsSection.Settings("EnableTools").Value()
            End If
        End If

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "



#End Region

End Class
